package com.htl.线程.sleep_wait;

import java.util.concurrent.TimeUnit;

/**
 *  一、如果 synchronized 修饰非静态方法，则锁定的就是方法调用者。（对象）
 */

public class Synchronized01 {
    public static void main(String[] args) {
        Date1 date1 = new Date1();
        new Thread(()->{
            date1.func1();
        },"A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            date1.func2();
        },"B").start();
    }
}

class Date1{
    public synchronized void func1(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("1...");
    }
    public synchronized void func2(){
        System.out.println("2...");
    }
}

